package com.atguigu.bigdata.spark.zzgcore.rdd.operator.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Classname Spark_01_RDD_Operator_Action
 * @Description TODO
 * @Date 2023/10/22 21:22
 * @Author zhuzhenguo
 */
object Spark_04_RDD_Operator_Action {
  def main(args: Array[String]): Unit = {
    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
//    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)

    val rdd: RDD[(String, Int)] = sc.makeRDD(List(
      ("a", 1), ("a", 2), ("a", 3)
    ))

    // countByValue:表述的是这个值出现的次数
//    val intToLong: collection.Map[Int, Long] = rdd.countByValue()
    val stringToLong: collection.Map[String, Long] = rdd.countByKey()
    println(stringToLong)
    sc.stop()
  }
}
